#!/bin/bash
source /home/shell/location.sh
# 自动部署tomcat脚本
main(){
location $0
ifSuccess $? '没有得到LOCATION的值退出'
cd $LOCATION
app=$1
version=$2
currentTime=$(date +%Y-%m-%d_%H-%M-%S)
url='https://gitee.com/zyl20190809/auto_deploy/raw/master/app_v1.0.war'
dir_download=$LOCATION/war
downloadWar $dir_download "${app}_$version.war" $url
unwar
/home/dev/app/tomcat/run/tomcat.sh restart
}
downloadWar(){
dir_download=$1
war_simplename=$2
war_url=$3
if [ ! -d dir_download ];then mkdir -p $dir_download
fi
curl $war_url > $dir_download/$war_simplename
ifSuccess $? '下载war失败'
echo '下载完成:'$dir_download/$war_simplename
war_filename=$dir_download/$war_simplename
unwar_dir=$dir_download
}
unwar(){
war_filename=${1:-"$war_filename"}
unwar_dir=${2:-"$unwar_dir"}
target_dir=$LOCATION/war/${app}_${version}_$currentTime
mkdir -p $target_dir
unzip -q $war_filename -d $target_dir
unziptarget=$target_dir/$(ls $target_dir)
echo '$unziptarget='$unziptarget
if [ -d appwar ] || [ -f appwar ];then 
rm -rf appwar;
echo 删除成功
fi
ln -sf $unziptarget appwar
echo '<?xml version="1.0" encoding="UTF-8" ?>
<Context docBase="'$LOCATION/appwar'" allowLinking="false">
</Context>' > $LOCATION/conf/Catalina/localhost/ROOT.xml
return $?
}
main $*